home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 October: Mac OS SDK / Dev.CD Oct 96 SDK / Dev.CD Oct 96 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / Draw / Sources / BaseShp.h < prev    next >
Encoding:
Text File  |  1996-08-16  |  9.9 KB  |  327 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                BaseShp.h
  4. //    Release Version:    $ ODF 1 $
  5. //
  6. //    Author:                Henri Lamiraux
  7. //
  8. //    Copyright:            (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  9. //
  10. //========================================================================================
  11.  
  12. #ifndef BASESHP_H
  13. #define BASESHP_H
  14.  
  15. #ifndef CONSTANT_H
  16. #include "Constant.h"
  17. #endif
  18.  
  19. // ----- Framework Layer -----
  20.  
  21. #ifndef FWSELECT_H
  22. #include "FWSelect.h"
  23. #endif
  24.  
  25. #ifndef FWSCPTBL_H
  26. #include "FWScptbl.h"
  27. #endif
  28.  
  29. // ----- OS Layer -----
  30.  
  31. #ifndef FWINK_H
  32. #include "FWInk.h"
  33. #endif
  34.  
  35. #ifndef FWSTYLE_H
  36. #include "FWStyle.h"
  37. #endif
  38.  
  39. #ifndef FWPOINT_H
  40. #include "FWPoint.h"
  41. #endif
  42.  
  43. #ifndef FWRECT_H
  44. #include "FWRect.h"
  45. #endif
  46.  
  47. // ----- Foundation Layer -----
  48.  
  49. #ifndef FWRUNTYP_H
  50. #include "FWRunTyp.h"
  51. #endif
  52.  
  53. #ifndef FWTCOLL_H
  54. #include "FWTColl.h"
  55. #endif
  56.  
  57. //========================================================================================
  58. // Forward Declarations
  59. //========================================================================================
  60.  
  61. class ODFacet;
  62. class ODShape;
  63. class CDrawPart;
  64. class CDrawPublishLink;
  65. class CDrawSubscribeLink;
  66. class FW_CGraphicContext;
  67. class FW_CMouseEvent;
  68. class FW_CRectShape;
  69. class FW_CPromise;
  70. class CDrawFacetClipper;
  71.  
  72. //========================================================================================
  73. // Constants
  74. //========================================================================================
  75.  
  76. enum ShapeType {
  77.     kLineShape = 1,
  78.     kRectShape = 2,
  79.     kOvalShape = 3,
  80.     kRRectShape = 4,
  81.     kTextShape = 5,
  82.     kProxyShape = 6,
  83.     kGroupShape = 7
  84. };
  85.  
  86. //========================================================================================
  87. // class CBaseShape
  88. //========================================================================================
  89.  
  90. class CBaseShape : public FW_MScriptable
  91. {
  92. public:
  93.     FW_DECLARE_CLASS
  94.     FW_DECLARE_AUTO(CBaseShape)
  95.  
  96. public:
  97.     virtual ~CBaseShape();
  98.  
  99.     virtual void        Removed(Environment* ev);
  100.     virtual void        Deleted(Environment* ev);
  101.     
  102.     // ----- Drawing -----
  103.     virtual void         RenderShape(Environment* ev, ODFacet* facet, FW_CGraphicContext& gc) = 0;
  104.     void                RenderHandles(FW_CGraphicContext& gc);
  105.     
  106.     // ----- Shape setting -----
  107.     FW_Fixed            GetPenSize() const;
  108.         
  109.     // ----- Selection -----
  110.     virtual FW_Boolean    HitTest(Environment *ev, FW_CGraphicContext& gc, const FW_CMouseEvent& theMouseEvent) const = 0;
  111.     FW_Boolean            InSelectionRect(const FW_CRect& rect) const;
  112.     
  113.     short                WhichHandle(FW_CGraphicContext& gc, const FW_CPoint& mouse) const;
  114.     
  115.     void                 CalcHandle(short whichHandle, FW_CRectShape* handle, const FW_CPoint& penSize) const;
  116.  
  117.     virtual void        SelectShape(Environment *ev, FW_Boolean state);
  118.     FW_Boolean            IsSelectedShape() const
  119.                             {return fSelected;}
  120.  
  121.     virtual void        RestoreShape(Environment *ev, CDrawPart* drawPart);
  122.     
  123.     // ----- Creation -----
  124.     virtual void         TrackFeedback(Environment* ev, ODFacet* facet, FW_CGraphicContext& gc, const FW_CPoint& anchorPoint, const FW_CPoint& currentPoint, FW_Boolean erase);
  125.     virtual void         SetShapeGeometry(const FW_CPoint& anchorPoint, const FW_CPoint& currentPoint) = 0;
  126.  
  127.     // ----- Promises -----
  128.     void                Promised(FW_EStorageKinds storageKind, FW_Boolean state);
  129.     FW_Boolean            IsPromised() const
  130.                             {return fPromised != 0;}
  131.     void                 CheckPromise(Environment* ev, FW_CPart* part);
  132.  
  133.     // ----- Drag -----
  134.     virtual void        OffsetShape(Environment *ev, FW_Fixed xDelta, FW_Fixed yDelta) = 0;
  135.     
  136.     // ----- Resize -----
  137.     FW_CStyle            GetResizeStyle() const;
  138.     virtual void        ResizeFeedback(FW_CGraphicContext& gc, const FW_CInk& ink, const FW_CStyle& style, 
  139.                                         short whichHandle, const FW_CPoint& mouseLoc) = 0;
  140.     virtual void        GetMapRects(short whichHandle, const FW_CPoint& lastLocation,
  141.                                     FW_CRect& srcRect, FW_CRect& dstRect) = 0;
  142.     virtual void        GetHandleCenter(short whichHandle, FW_CPoint& center) const = 0;
  143.     virtual void        MapShape(Environment *ev, CDrawPart* part, const FW_CRect& srcRect, const FW_CRect& dstRect) = 0;
  144.     
  145.     void                GetUpdateBox(Environment* ev, ODShape *updateBox) const;
  146.     void                GetUpdateBox(FW_CRect& updateBox) const;
  147.     void                GetDragRect(FW_CRect& dragRect) const;
  148.     
  149.     virtual ODShape*    CreateShapeOutline(Environment *ev) = 0;
  150.     virtual void        GetClipRegion(Environment* ev, ODShape* clipRegion) = 0;
  151.     virtual FW_CRect    GetRectGeometry() const = 0;
  152.     
  153.     virtual void        SubtractToWindowClip(Environment *ev, 
  154.                                             CDrawFacetClipper* facetClipper, 
  155.                                             ODFacet* containingFacet, 
  156.                                             ODShape* windowClip,
  157.                                             ODShape* tempShape);
  158.     
  159.     // ----- z-Order -----
  160.     virtual void         MovedAfter(Environment* ev, CBaseShape* shape);
  161.     virtual void         MovedBefore(Environment* ev, CBaseShape* shape);
  162.     virtual void         MovedFirst(Environment* ev);
  163.     virtual void         MovedLast(Environment* ev);
  164.     
  165.     // ----- Persistence -----
  166.     virtual void         Flatten(FW_CWritableStream& archive);
  167.     
  168.     // ----- Cache -----
  169.     void                ClearCache();
  170.     
  171.     // ----- Linking -----
  172.     virtual void        SetPublishLink(Environment* ev, 
  173.                             CDrawPublishLink* publishLink);
  174.     CDrawPublishLink*    GetPublishLink() const
  175.                             {return fPublishLink;}
  176.     FW_Boolean            IsPublished() const
  177.                             {return fPublishLink != NULL;}
  178.                             
  179.     virtual void        SetSubscribeLink(Environment* ev, 
  180.                             CDrawSubscribeLink* subscribeLink);
  181.     CDrawSubscribeLink*    GetSubscribeLink() const
  182.                             {return fSubscribeLink;}
  183.     FW_Boolean            IsSubscribed() const
  184.                             {return fSubscribeLink != NULL;}
  185.     virtual FW_Boolean    IsInLinkDestination(Environment* ev);
  186.                             
  187.     short                GetExternalizationIndex()
  188.                             { return fExternalizationIndex; }
  189.     void                SetExternalizationIndex(short index)
  190.                             { fExternalizationIndex = index; }
  191.                             
  192.     // ----- Getters/Setters -----
  193.     virtual FW_Boolean    SetFrozen(FW_Boolean state);
  194.     virtual FW_Boolean IsFrozen() const;
  195.     
  196.     FW_Boolean            HasFillStyle() const
  197.                             {return (fRenderVerb & kFillOnly) != 0;}
  198.     FW_Boolean            FillOnly() const
  199.                             {return fRenderVerb == kFillOnly;}
  200.     FW_Boolean            HasFrameStyle() const
  201.                             {return (fRenderVerb & kFrameOnly) != 0;}
  202.     FW_Boolean            FrameOnly() const
  203.                             {return fRenderVerb == kFrameOnly;}
  204.     FW_Boolean            HasFrameAndFillStyle() const
  205.                             {return (fRenderVerb == kFillFrame);}
  206.                                                         
  207.     void                GetColor(FW_Boolean fill, FW_CColor& color);
  208.     FW_CPattern            GetPattern(FW_Boolean fill);
  209.     unsigned short        GetRenderVerb()
  210.                             { return fRenderVerb; };
  211.                         
  212.     short                GetNumberOfHandles() const
  213.                             {return fNumberOfHandles;}
  214.     ShapeType            GetShapeType() const
  215.                             {return (ShapeType)fShapeType;}
  216.     
  217.     void                SetFrameInk(const FW_CInk& ink)
  218.                             {fFrameInk = ink;}
  219.     void                SetFrameStyle(const FW_CStyle& style)
  220.                             {fFrameStyle = style;}
  221.     void                SetFillInk(const FW_CInk& ink)
  222.                             {fFillInk = ink;}
  223.     void                SetFillStyle(const FW_CStyle& style)
  224.                             {fFillStyle = style;}
  225.     
  226.     virtual void        ChangeFrameColor(Environment* ev, CDrawPart* part, const FW_CColor& color);
  227.     virtual void        ChangeFramePattern(Environment* ev, CDrawPart* part, const FW_CPattern& pattern);
  228.  
  229.     virtual void        ChangeFillColor(Environment* ev, CDrawPart* part, const FW_CColor& color);
  230.     virtual void        ChangeFillPattern(Environment* ev, CDrawPart* part, const FW_CPattern& pattern);
  231.  
  232.     virtual void        ChangePenSize(Environment* ev, CDrawPart* part, FW_Fixed newPenSize);
  233.     virtual void        ChangeRenderVerb(Environment* ev, CDrawPart* part, unsigned short renderVerb);
  234.  
  235.     FW_CInk                UnshareInk(const FW_CInk& ink) const;
  236.     FW_CStyle            UnshareStyle(const FW_CStyle& style) const;
  237.     
  238.     virtual void        AdjustRectForPenSize(FW_CRect& rect, FW_Fixed penSize) const;
  239.  
  240.     // ----- Semantic Object -----
  241.     
  242.     virtual ODDescType    GetObjectClass() const;
  243.     
  244.     virtual FW_Boolean    HasProperty(ODDescType whichProperty) const;
  245.     
  246.     virtual FW_Boolean    GetProperty(Environment* ev, 
  247.                                     FW_CPart* part, 
  248.                                     FW_CDesc& propertyValue, 
  249.                                     ODDescType whichProperty, 
  250.                                     ODDescType desiredType) const;
  251.                                     
  252.     virtual void        SetProperty(Environment* ev, 
  253.                                     FW_CPart* part, 
  254.                                     FW_CDesc& propertyValue, 
  255.                                     ODDescType whichProperty);    
  256.                                                         
  257.     virtual void        GetUndoStrings(Environment* ev,
  258.                                     FW_CPart* part,
  259.                                     ODDescType whichProperty, 
  260.                                     FW_CString& undoString, 
  261.                                     FW_CString& redoString) const;
  262.     
  263.     // ----- Archiving -----
  264.     static void*         Read(FW_CReadableStream& stream, FW_ClassTypeConstant type);
  265.     static void         Write(FW_CWritableStream& stream, FW_ClassTypeConstant type, const void *object);
  266.  
  267. protected:
  268.     CBaseShape(short numberOfHandles, unsigned short shapeType, unsigned short renderVerb);
  269.     CBaseShape(FW_CReadableStream& archive);
  270.     
  271.     void                 InitStatic();
  272.     
  273. public:        
  274.     static FW_CRectShape*                gWorkingHandle;
  275.     static unsigned long                 gShapeCount;
  276.  
  277. protected:
  278.     unsigned short                        fPromised;
  279.     
  280.     FW_CInk                                fFrameInk;
  281.     FW_CInk                                fFillInk;
  282.     FW_CStyle                            fFrameStyle;
  283.     FW_CStyle                            fFillStyle;
  284.     
  285.     unsigned short                        fRenderVerb;
  286.  
  287.     unsigned short                        fShapeType;
  288.     
  289.     FW_Boolean                            fSelected;
  290.     short                                fNumberOfHandles;
  291.     CDrawPublishLink*                    fPublishLink;
  292.     CDrawSubscribeLink*                    fSubscribeLink;
  293.     short                                fExternalizationIndex;    // used by links to identify their shapes
  294. };
  295.  
  296. //========================================================================================
  297. // class CShapeCollection
  298. //========================================================================================
  299.  
  300. class CShapeCollection : public FW_TOrderedCollection<CBaseShape>
  301. {
  302. public:
  303.     FW_DECLARE_AUTO(CShapeCollection)
  304.     
  305.     CShapeCollection() :
  306.         FW_TOrderedCollection<CBaseShape>(){}
  307.     ~CShapeCollection() {}
  308. };
  309.  
  310.  
  311.  
  312. //========================================================================================
  313. // class CShapeCollectionIterator
  314. //========================================================================================
  315.  
  316. class CShapeCollectionIterator : public FW_TOrderedCollectionIterator<CBaseShape>
  317. {
  318. public:
  319.     FW_DECLARE_AUTO(CShapeCollectionIterator)
  320.     
  321.     CShapeCollectionIterator(CShapeCollection* collection) :
  322.         FW_TOrderedCollectionIterator<CBaseShape>(collection){}
  323.     ~CShapeCollectionIterator() {}
  324. };
  325.  
  326. #endif
  327.